package cn.swjtuhc.ss.hljapi.controller;

import cn.swjtuhc.ss.hljapi.client.AliyunOssClient;
import cn.swjtuhc.ss.hljapi.common.Result;
import cn.swjtuhc.ss.hljapi.mapper.EssayMapper;
import cn.swjtuhc.ss.hljapi.pojo.Essay;
import cn.swjtuhc.ss.hljapi.util.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 程序狗没有春天
 * @version 1.00
 * @createTime 2024/8/28 15:37
 */
@Slf4j
@RequestMapping("/api/upload")
@RestController
public class UploadController {
    @Autowired
    private AliyunOssClient aliyunOssClient;
    @PostMapping("/activity")

    public Result activity(@RequestParam("file") MultipartFile image) {
        log.info("上传成功,文件名:{}",image.getOriginalFilename());
        String url = aliyunOssClient.upload(image , Constants.ACTIVITY_IMG_PREFIX);
        return Result.success(url);
    }
    @PostMapping("/volunteer")
    public Result volunteer(@RequestParam("file") MultipartFile image) {
        log.info("上传成功,文件名:{}",image.getOriginalFilename());
        String url = aliyunOssClient.upload(image , Constants.VOLUNTEER_IMG_PREFIX);
        return Result.success(url);
    }
    @PostMapping("/essay")
    public Result essay(@RequestParam("file") MultipartFile image) {
        log.info("上传成功,文件名:{}",image.getOriginalFilename());
        String url = aliyunOssClient.upload(image , Constants.VOLUNTEER_IMG_PREFIX);
//        Essay essay = new Essay();
//        essay.setId(id);
//        essay.setPicture(url);
//        int i = essayMapper.updateById(essay);
//
//        System.out.println(essay.toString());
        return Result.success(url);
    }

    @PostMapping("/avatar")
    public Result avatar(@RequestParam("file") MultipartFile image) {
        log.info("上传成功,文件名:{}",image.getOriginalFilename());
        String url = aliyunOssClient.upload(image , Constants.AVATAR_IMG_PREFIX);
        return Result.success(url);
    }
}
